/**
 * Created by CYT on 2017/10/10.
 */
$(document).ready(function () {
    var userPhone;
    var userEmail;
    var password;
    var re_password;

    $("#confirm").click(function () {
        var mark = false;
        userPhone = $("#phone").val();
        userEmail = $("#email").val();
        $.ajax({
            url: "/print_cyt/changCode",
            type: "post",
            data: {
                userPhone: userPhone,
                userEmail: userEmail
            },
            success: function (data) {
                if (data === true) {//手机号和邮箱都正确。
                    $("#password").blur(function () {
                        password = $("#password").val();
                        if (!/^.{6,}$/.test(password)) {/*判断密码：至少6个字符*/
                            $("#p_password").text("至少输入6个字符");
                            $("#password").val();
                            mark = false;
                        }
                        else {
                            $("#p_password").text("");
                            mark = true;
                        }
                    })
                    $("#re_password").blur(function () {
                        re_password = $("#re_password").val();
                        if (password !== re_password) {
                            $("#p_re_password").text("密码不一致，请重新输入");
                            $("#re_password").val();
                            mark = false;
                        }
                        else {
                            $("#p_re_password").text("");
                            mark = true;
                        }
                    })
                    if (mark === true) {
                        $.ajax({
                            url: "/print_cyt/updateUserInfo",
                            type: "post",
                            data: {
                                userCode: password,
                            },
                            success: function (data) {
                                if (data.ajaxInfo==="Success"){
                                    alert("密码修改成功，请重新登陆");
                                    window.location.href = "../logIn/logIn.html"
                                }
                            }
                        })
                    }
                }
                else {
                    alert("邮箱或手机号错误，请重新输入");
                }
            }
        })
    })
})